package Picture.dao.impl;

import Picture.dao.PictureDao;
import Picture.entiy.Picture;
import dao.BaseDao;
import order.entity.OrderTable;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class PictureDaoIml extends BaseDao implements PictureDao {
    @Override
    public List<Picture> getList() {
        String sql="SELECT SUM(b.price) \n" +
                "FROM Orderbiao a \n" +
                "INNER JOIN Detailsdb b ON a.id = b.Detailsid \n" +
                "WHERE TIME(a.timeorder) BETWEEN '00:00' AND '23:59';\n";
        ResultSet rs=this.executeQuery(sql);
        List<Picture> list=new ArrayList<>();

        try {
            while (rs.next()){
                list.add(new Picture(rs.getInt(1)));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            this.closeConnection(null,null,rs);
        }
        return list;
    }

    @Override
    public double sumAmout(String beginTime, String endTime) {
        String sql="SELECT SUM(b.price) \n" +
                "FROM Orderbiao a \n" +
                "INNER JOIN Detailsdb b ON a.id = b.Detailsid \n" +
                "WHERE a.timeorder BETWEEN ? AND ?;\n";
        ResultSet rs=this.executeQuery(sql,beginTime,endTime);
       double result=0;

        try {
            while (rs.next()){
                result=rs.getDouble(1);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            this.closeConnection(null,null,rs);
        }
        return result;
    }
}
